package secret

import (
	"strconv"
)

const testVersion = 1

// secretMap
var secretMap = map[int]string{
	0: "wink",
	1: "double blink",
	2: "close your eyes",
	3: "jump",
}

// ArrayReserve
func ArrayReserve(input []string) (r []string) {
	length := len(input)
	r = make([]string, length)
	for i := 0; i < length; i++ {
		r[i] = input[length-1-i]
	}

	return r
}

// Handshake
func Handshake(input uint) (r []string) {
	b := DecimalToBinary(input)
	length := len(b)
	if length > 4 {
		length = 4
	}
	for i := 0; i < length; i++ {
		if b[i:i+1] == "1" {
			r = append(r, secretMap[i])
		}
	}

	if input > 16 {
		r = ArrayReserve(r)
	}
	return
}

// DecimalToBinary
func DecimalToBinary(input uint) (r string) {
	input = input % 32
	i := int(input)
	for {
		r = r + strconv.Itoa(i%2)

		i = i / 2
		if i == 0 {
			break
		}
	}

	return
}
